<template>
  <view class="contain">
    <u-modal v-model="modelshow"  :title-style="{fontsize: '33rpx'}" :show-cancel-button=true  >
			<view class="slot-content" >
				<rich-text :nodes="content"></rich-text>
			</view>
		</u-modal>
      <u-modal v-model="modeltrue"  :title-style="{fontsize: '33rpx'}" :show-cancel-button=true @confirm='modelshowclick()' >
			<view class="slot-content" >
				<rich-text :nodes="content"></rich-text>
			</view>
		</u-modal>
    <view class="top-content"></view>
    <view class="top">
      <view v-for="(item, index) in data" :key="index" class="card">
        <view @click="enter(item)">
          <card :data="item" :phone='phone'/>
        </view>
      </view>
    </view>

    <!-- <view style="height: 60px"></view> -->

    <view class="footer">
      <u-button
        v-if="data.some(v=>v.needCheckNum!=0)"
        class="btn"
        @click="handleClick()"
        type="primary"
        :ripple="true"
        ripple-bg-color="#32afff"
      >一键完成</u-button>
      <u-button
        v-else
        class="btn"
        type="primary"
        :ripple="true"
        ripple-bg-color="#32afff"
        @click="handleTable()"
      >生成报告</u-button>
    </view>
  </view>
</template>

<script>
import card from "@/components/detail/crad.vue";
import {
  pointCheckDeviceDetail,
  pointCheckTaskDeviceAdd,
  pointCheckTaskDeviceEdit,
  pointCheckTaskDeviceRemove,
  pointCheckTaskDeviceQuickCreateReport,
  devicePointCheckConfig
} from "@/api/index.js";
export default {
  components: {
    card
  },
  onLoad(val) {
    this.taskId = val.taskDeviceId;
    this.Tdata = val.taskDeviceId;
    this.id = val.Id;
    this.timeone = val.timeone;
    this.hour = val.hour;
    this.minute = val.minute;
    this.category = val.category;
    this.second = val.second;
    this.productId = val.productId;
    this.phone = val.phone;
    this.manufacturer = val.manufacturer;
    this.projectId = val.projectId;
    this.deviceId = val.deviceId;
    uni.setNavigationBarTitle({
      title: "详情"
    });
  },
  onShow() {
    this.show = true;
    this.getList();
  },
  data() {
    return {
      show: true,
      modeltrue: false,
      taskId: "",
      id: "",
      length: 0,
      obj: {},
      data: [],
      data2:[],
      modelshow: false,
      category: 0,
      content: ``,
      deviceId:"",
    };
  },
  methods: {
    getList() {
      uni.showLoading({
        title: "加载中"
      });
      this.data = [];
      this.length = 0;
      let show = true;
        pointCheckDeviceDetail(this.Tdata).then(res => {
          for (let i in res.data) {
            if (res.data[i].textItem) {
              if (res.data[i].textItem.length > 0) {
                this.obj[i] = res.data[i].textItem.toString();
              }
            }
            res.data[i].name = i;
            this.data.push(res.data[i]);
            if (res.data[i].needCheckNum == 0) {
              show = false;
            } else {
              show = true;
            }
          }
          if (show == false) {
          }
        });
        uni.hideLoading();
    },
    enter(ite) {
      console.log(ite.pointCheckDeviceDetails[0].category)
      uni.navigateTo({
        url:
          "/pages/detaildemo/detaildemo?id=" +
          this.id +
          "&taskId=" +
          this.taskId +
          "&name=" +
          ite.name +
          "&productId=" +
          this.productId +
          "&phone=" +
          this.phone +
          "&projectId=" +
          this.projectId +
          "&manufacturer=" +
          this.manufacturer +
          "&ite=" +
          JSON.stringify(ite)
      });
    },
    handleClick() {
      var b = JSON.stringify(this.obj) == "{}";
      this.content = "";
      this.content += "确定将其他项全部标记为已完成？";
      this.modeltrue = true;
    },
    modelshowclick() {
      pointCheckTaskDeviceQuickCreateReport(this.Tdata).then(res2 => {
        this.getList();
      });
      this.show = false;
    },
    handleTable() {
      uni.navigateTo({
        url:
          "/pages/vtable/vtable?id=" +
          this.Tdata +
          "&timeone=" +
          this.timeone +
          "&hour=" +
          this.hour +
          "&minute=" +
          this.minute +
          "&second=" +
          this.second +
          "&phone=" +
          this.phone +
          "&manufacturer=" +
          this.manufacturer +
          "&taskId=" +
          this.id +
          "&taskDeviceId=" +
          this.taskId +
          "&deviceId=" +
          this.deviceId+
          "&category=" +
          this.category
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.contain {
  height: 100%;

  position: relative;
  background-color: white;
}
.top-content {
  height: 160upx;
  background: linear-gradient(to left, #1040be, #026dff);
}
.top {
  height: calc(100% - 200rpx);
  overflow-y: auto;
  position: absolute;
  background-color: white;
  padding: 30rpx;
  width: 100%;
  top: 50rpx;
  border-radius: 40rpx 40rpx 0 0;
  .card {
    // background-color: white;
    border: 1px solid #eee;
    padding: 20rpx 20rpx;
    border-radius: 25rpx;
    box-shadow: 0 0 20rpx #eee;
    margin-bottom: 20rpx;
  }
}
.btn {
  width: 544rpx;
  height: 91rpx;
  background: linear-gradient(-34deg, #1040be, #026dff);
  border-radius: 46rpx;
  font-size: 36rpx;
  font-weight: 500;
  color: #ffffff;
}
.slot-content {
  font-size: 32rpx;
  color: $u-content-color;
  // color:red;
  padding: 30rpx;
}
/deep/ .u-model__title {
  font-size: 42rpx;
}
</style>
